package com.hairline.hairlinemarket.service.impl;

import com.hairline.hairlinemarket.bean.MarketSystem;
import com.hairline.hairlinemarket.bean.MarketSystemExample;
import com.hairline.hairlinemarket.mapper.MarketSystemMapper;
import com.hairline.hairlinemarket.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Author:杨小凯
 * Date:2023-04-20 19:43
 * Description:<描述>
 */
@Service
public class SystemServiceImpl implements SystemService {

    @Autowired
    private MarketSystemMapper systemMapper;
    /*
    查询new的数值
     */
    @Override
    public Integer getNewLimit() {
        List<MarketSystem> marketSystems = systemMapper.selectByExample(new MarketSystemExample());
        for (MarketSystem marketSystem : marketSystems) {
            if ("market_wx_index_new".equals(marketSystem.getKeyName())){
                return Integer.parseInt(marketSystem.getKeyValue());
            }
        }
        return null;
    }

    @Override
    public Integer getHotLimit() {
        List<MarketSystem> marketSystems = systemMapper.selectByExample(new MarketSystemExample());
        for (MarketSystem marketSystem : marketSystems) {
            if ("market_wx_index_hot".equals(marketSystem.getKeyName())){
                return Integer.parseInt(marketSystem.getKeyValue());
            }
        }
        return null;
    }

    @Override
    public Integer getBrandLimit() {
        List<MarketSystem> marketSystems = systemMapper.selectByExample(new MarketSystemExample());
        for (MarketSystem marketSystem : marketSystems) {
            if ("market_wx_index_brand".equals(marketSystem.getKeyName())){
                return Integer.parseInt(marketSystem.getKeyValue());
            }
        }
        return null;
    }

    @Override
    public Integer getTopicLimit() {
        List<MarketSystem> marketSystems = systemMapper.selectByExample(new MarketSystemExample());
        for (MarketSystem marketSystem : marketSystems) {
            if ("market_wx_index_topic".equals(marketSystem.getKeyName())){
                return Integer.parseInt(marketSystem.getKeyValue());
            }
        }
        return null;
    }

    @Override
    public Integer getCatLogLimit() {
        List<MarketSystem> marketSystems = systemMapper.selectByExample(new MarketSystemExample());
        for (MarketSystem marketSystem : marketSystems) {
            if ("market_wx_catlog_list".equals(marketSystem.getKeyName())){
                return Integer.parseInt(marketSystem.getKeyValue());
            }
        }
        return null;
    }

    @Override
    public Integer getCatlogListLimit() {
        List<MarketSystem> marketSystems = systemMapper.selectByExample(new MarketSystemExample());
        for (MarketSystem marketSystem : marketSystems) {
            if ("market_wx_catlog_list".equals(marketSystem.getKeyName())){
                return Integer.parseInt(marketSystem.getKeyValue());
            }
        }
        return null;
    }

    @Override
    public Integer getCatlogMoreLimit() {
        List<MarketSystem> marketSystems = systemMapper.selectByExample(new MarketSystemExample());
        for (MarketSystem marketSystem : marketSystems) {
            if ("market_wx_catlog_goods".equals(marketSystem.getKeyName())){
                return Integer.parseInt(marketSystem.getKeyValue());
            }
        }
        return null;
    }

    @Override
    public Boolean isAutoCreateShareImage() {
        List<MarketSystem> marketSystems = systemMapper.selectByExample(new MarketSystemExample());
        for (MarketSystem marketSystem : marketSystems) {
            if ("market_wx_share".equals(marketSystem.getKeyName())){
                return "true".equals(marketSystem.getKeyValue());
            }
        }
        return null;
    }
}
